<?php
  if ($_GET['logout']==1) {
    unset($_SESSION['valid_login']);
  }
  else {
?>
<table width="100%">
  <tr>
    <td class="style3">
    	<a href="frontpage.php">Home</a>>
      <a href="show_depart.php">Departments</a>>
      <?php
          $link = mysql_connect('', 'admin_xbq', 'nihao')
              or die('Could not connect: ' . mysql_error());
          //echo "Connected successfully\n";
          //汉字你好更换退货将
          mysql_query('use test');
          if (isset($_GET['sr_id'])) {
            $sql = 'select depart_ID, sr_short_name from staffroom where staffroom.sr_ID='.$_GET['sr_id'].';';
            $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
            $line = mysql_fetch_array($result, MYSQL_ASSOC);
            $depart = $line['depart_ID'];
            $sr = $_GET['sr_id'];
            $name = $line['sr_short_name'];
          }
          else {
            $sql =  'SELECT depart_ID, sr_short_name FROM staffroom WHERE staffroom.sr_ID = 
            ( SELECT sr_ID FROM user WHERE user.user_ID = '.$_GET['user_id'].');';
            $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
            $line = mysql_fetch_array($result, MYSQL_ASSOC);
            $depart = $line['depart_ID'];
            $name = $line['sr_short_name'];
            $sql = 'select sr_ID from user where user.user_ID='.$_GET['user_id'];
            $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
            $line = mysql_fetch_array($result, MYSQL_ASSOC);
            $sr = $line['sr_ID'];
          }
          
          mysql_close($link);
      ?>
      <a href="show_staffroom.php?d_id=<?php echo $depart;?>">Staff room</a>>
      <a href="show_teacher.php?sr_id=<?php echo $sr;?>">
        Teacher in <?php echo $name;?>
      </a>
    </td>
    <?php
      }
    ?>
    <td class="style3" align="right">
    	<a href="<?echo $_SERVER['PHP_SELF'];?>?logout=1">Sign out</a>
    </td>
  </tr>
</table>
